#include "pch.h"
#include "seMenuHero.h"

//const sf::Input& mInputHero = app.GetInput(); 

void seMenuHero::Load(int number)
{
type=number-1;
frames=6;
if (number==1){
	leftKey='q';
	rightKey='w';
}else{
	leftKey='o';
	rightKey='p';
}
string tmp;
sprintf((char*)tmp.c_str(), "%d", number);
string str = tmp.c_str();
for (int a=0;a<frames;a++){
	string actual;
	sprintf((char*)actual.c_str(), "%d", a);
	string actualny = actual.c_str();
	if (type==1) 
		mBackgroundLeft[a].LoadFromFile("data/heroM"+str+"_left_"+actualny+".png");
	else
		mBackgroundRight[a].LoadFromFile("data/heroM"+str+"_right_"+actualny+".png");
}
if (type==1) 
	mActiveSprite.SetImage(mBackgroundLeft[0]);
else
	mActiveSprite.SetImage(mBackgroundRight[0]);
//mBackRight.LoadFromFile("data/hero"+str+"_"+"right.png");
//mActiveSprite.SetImage(mBackFront);
//sf::Vector2f scalevec(0.3f, 0.3f);
//mActiveSprite.SetScale(scalevec);
}

void seMenuHero::Init()
{
	counter=0;
	iCurrentFrame = 0;
	//mActiveSprite.SetImage(mBackground[iCurrentFrame]);
	if (type==0){
		sf::Vector2f v1(viewWidth/2-500.0f,viewHeight- mActiveSprite.GetSize().y -25.0f);
		mActiveSprite.SetPosition(v1);
	}
	else{
		sf::Vector2f v1(viewWidth/2+280.0f, viewHeight- mActiveSprite.GetSize().y -265.0f);
		mActiveSprite.SetPosition(v1);
	}
}

void seMenuHero::Step(bool move)
{
	iCurrentFrame++;
	if (iCurrentFrame>=frames)
		iCurrentFrame=0;
	sf::Vector2f actual = mActiveSprite.GetPosition();
	if (move){
		if (actual.x>(-300.0f) && type==1){
				sf::Vector2f v1(actual.x-10, actual.y);
				mActiveSprite.SetPosition(v1);
				mActiveSprite.SetImage(mBackgroundLeft[iCurrentFrame]);
		}
		else if (actual.x<viewWidth && type==0){
				sf::Vector2f v1(actual.x+10, actual.y);
				mActiveSprite.SetPosition(v1);
				mActiveSprite.SetImage(mBackgroundRight[iCurrentFrame]);
		}
	}
}

void seMenuHero::Draw()
{
	app.Draw(mActiveSprite);
}